package com.bsb.biz.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bsb.base.mapper.SysUserRoleMapper;
import com.bsb.base.model.SysUserRole;
import com.bsb.base.model.SysUserRoleExample;
import com.bsb.base.model.SysUserRoleExample.Criteria;

@Service
public class SysUserRoleService{
	
	@Resource
	private SysUserRoleMapper sysUserRoleMapper;
	
	public void addSysUserRole(SysUserRole sysUserRole) {
		sysUserRoleMapper.insertSelective(sysUserRole);
	}
	
	public void delSysUserRoleById(Long id) {
		sysUserRoleMapper.deleteByPrimaryKey(id);
	}
	
	public void updateSysUserRole(SysUserRole sysUserRole) {
		sysUserRoleMapper.updateByPrimaryKeySelective(sysUserRole);
	}
	
	public void updateSysUserRoleByExample(SysUserRole sysUserRole,SysUserRoleExample sysUserRoleExample){
	    sysUserRoleMapper.updateByExampleSelective(sysUserRole,sysUserRoleExample);
	}
	
	public SysUserRole getSysUserRoleById(Long id) {
		return sysUserRoleMapper.selectByPrimaryKey(id);
	}
	
	public List<SysUserRole> getPageSysUserRole(SysUserRoleExample sysUserRoleExample) {
		return sysUserRoleMapper.selectPage(sysUserRoleExample);
	}
	
	public int countSysUserRole(SysUserRoleExample sysUserRoleExample) {
		return sysUserRoleMapper.countByExample(sysUserRoleExample);
	}
	
	public List<SysUserRole> selectByExample(SysUserRoleExample example){
	    return sysUserRoleMapper.selectByExample(example);
	}
	/**
	 * 用户的角色
	 * @param id
	 * @return
	 */
	public List<Long> queryRoleIdList(Long id) {
		return sysUserRoleMapper.queryRoleIdList(id);
	}
	
	public void insertBatchUserRole(Long userId,List<String> roleList){
		for (String roleid : roleList) {
			SysUserRole userrole = new SysUserRole();
			userrole.setUser_id(userId);
			userrole.setRole_id(Long.valueOf(roleid));
			sysUserRoleMapper.insertSelective(userrole);
		}
	}
}
